package eu.telecom_bretagne.RECRUT.servlet;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import eu.telecom_bretagne.RECRUT.service.IServiceDossierCandidature;

/**
 * Servlet implementation class ValidationRH
 */
@WebServlet("/valider_rh")
public class ValidationRH extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ValidationRH() {
        super();
    }


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
    protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String idD = request.getParameter("idD");
		String idE = request.getParameter("idE");
		String[] ids = request.getParameterValues("valider_rh");
		if (ids == null) {
			response.sendRedirect("index.jsp");
			return;
		}
		try {
			int idDossier = Integer.parseInt(idD); 
			int idEmploye = Integer.parseInt(idE);
			InitialContext ctx = new InitialContext();
			IServiceDossierCandidature serviceDossierCandidature = (IServiceDossierCandidature) ctx
					.lookup(IServiceDossierCandidature.JNDI_NAME);
			serviceDossierCandidature.validerDossierRH(idDossier, idEmploye);
			;
		} catch (NamingException e) {
			throw new ServletException(e);
		}
		response.sendRedirect("index.jsp");
	}

}
